package com.event.ingestion;

import java.util.Arrays;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;

/**
 * @author ZzHh
 * @Classname Driver
 * @Description TODO
 * @Date 2020/6/12 10:26
 * @Create by IntelliJ IDEA
 **/

/**
 * 驱动类
 * 程序运行类
 */
public class Driver implements CommandLineRunner {
    //程序入口
    public static void main(String[] args) {
        SpringApplication.run(Driver.class,args);
    }

    //运行指定的class
    //java -jar  com.event.ingestion.kafka.EventProducer 1 2 3
    @Override
    public void run(String... strings) throws Exception {
        if ((strings == null) || (strings.length < 1)) {
            throw new Exception("请指定需要执行的类!");
        }
        Object o = Class.forName(strings[0]).newInstance();
        if (o instanceof IngestionExecutor) {
            ((IngestionExecutor)o).executor(Arrays.copyOfRange(strings,1,strings.length));
        }else{
            throw new Exception("指定的执行程序不是IngestionExecutor的实例!");
        }

    }
}